# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: schuay <jakob.gruber@gmail.com>
# Contributor: Mike Sampson <mike at sambodata dot com>
# Contributor: Adrian Stratulat <adrian.stratulat at inboxcom>
# Contributor: Anton Bazhenov <anton.bazhenov at gmail>
# Contributor: KillaB <xGenoBlast@gmail.com>
# Contributor: Callan Barrett <wizzomafizzo@gmail.com>
# Contributor: Christian Schmidt <xmucknertx@googlemail.com>
# Contributor: Sebastian Sareyko <public@nooms.de>

pkgname=angband
pkgver=4.2.4
pkgrel=2
pkgdesc='A roguelike dungeon exploration game based on the writings of JRR Tolkien'
arch=('loong64' 'x86_64')
url='https://rephial.org/'
license=('GPL2' 'custom')
depends=(
  'sdl2'
  'sdl2_ttf'
  'sdl2_image'
  'sdl2_mixer'
  'ncurses'
  'xorg-fonts-misc'
  'xorg-mkfontscale'
  'hicolor-icon-theme'
)
makedepends=('git' 'python-docutils')
_commit='ae4c7293778346b4307583911537c2db4401397f'
source=("$pkgname::git+https://github.com/angband/angband#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # fix icons & desktop files
  git cherry-pick --no-commit 167668321504e2a585882487842f032cc5956507
}

build() {
  cd "$pkgname"

  ./autogen.sh

  ./configure \
    --prefix=/usr \
    --bindir=/usr/bin \
    --sysconfdir=/usr/share/angband \
    --enable-sdl2 \
    --enable-sdl2-mixer

  make
}

package() {
  cd "$pkgname"

  make DESTDIR="$pkgdir" install

  # license
  install -vDm644 docs/copying.rst "$pkgdir/usr/share/licenses/$pkgname/COPYING"


  # see above cherry pick in prepare()
  # hopefully the following is fixed by next release
  pushd "$pkgdir/usr/share/angband/icons"
  # application icons
  for i in 16 32 128 256 512; do
    install -vDm644 "att-${i}.png" "$pkgdir/usr/share/icons/hicolor/${i}x${i}/apps/$pkgname.png"
  done

  # desktop files
  install -vDm644 -t "$pkgdir/usr/share/applications" angband-{x11,sdl2}.desktop

  # metainfo
  install -vDm644 -t "$pkgdir/usr/share/metainfo" angband.metainfo.xml
  popd
}
